package com.lin.mybatisdubbomysql.aop;

import com.lin.mybatisdubbomysql.enums.DateBaseEnum;
import com.lin.mybatisdubbomysql.extend.DynamicDataSource;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @author 九分石人
 */
@Component
@Aspect
public class DatasourceAspect {


    @Pointcut("execution(public * com.lin.mybatisdubbomysql.dal.mapper.databasetwo..*.*(..))")
    public void dataSourcePointCut() {

    }

    @Around("dataSourcePointCut()")
    public Object around(ProceedingJoinPoint point) throws Throwable {
        DynamicDataSource.setDataSource(DateBaseEnum.DataBaseTwo.getValue());
        try {
            return point.proceed();
        } finally {
            DynamicDataSource.clearDataSource();
        }
    }
}
